<?php
class RedirectController extends Zend_Controller_Action {
	public function indexAction() {
		$this->_helper->layout ()->disableLayout ();
		$this->_helper->viewRenderer->setNoRender ();
		$authData = Zend_Auth::getInstance ()->getIdentity();
		if (is_array($authData) and $authData['identity'] != 'anon' and $authData) {
		    //User is logged in
		    //Zend_Registry::get("logger")->debug($authData);
		    $userSession = new Zend_Session_Namespace('userSession');
		    $userRoles = $authData['roles'];
		    if (array_search('admin', $userRoles)) {
		        $userSession->userHome = '/admin/home';
		        return $this->_helper->redirector ( 'index', 'home','admin' );
		    } elseif (array_search('recruiter', $userRoles)) {
		        $userSession->userHome = '/recruiter/home';
		        return $this->_helper->redirector ( 'index', 'home','recruiter' );
		    } elseif (array_search('jobseeker', $userRoles)) {
		        $userSession->userHome = '/jobseeker/home';
		        return $this->_helper->redirector ( 'index', 'home','jobseeker' );
		    } else {
		        $userSession->userHome = '';
		        return $this->_helper->redirector ( 'index', 'index','default' );
		    }
		} else {
		    $authData = Zend_Auth::getInstance()->getIdentity();
		    //Zend_Registry::get("logger")->debug('Unable to meet criteria. Kindly contact administrator.');
		    //Zend_Registry::get("logger")->debug($authData);
		    return $this->_helper->redirector ( 'index', 'index','default' );
		    //return $this->_helper->redirector ( 'index', 'index' );
		}
	}
	
}